Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

32

Scanner reader = new Scanner(System.in);


System.out.println("enter your name");
String name=reader.next();
int count=0;
char letter= name.charAt(0);
while (something!=letter) {
System.out.println("enter a char, any char!");
char something = reader.next().charAt(0);
count++;}
System.out.println(count);

33
Scanner in = new Scanner(System.in);
double i = in.nextDouble(), last=i;
int count=0;

while (i!=0) {
if (last>i) count++;
last = i;
i = in.nextDouble(); }
System.out.printf("the number is %d",count);

34
Scanner in = new Scanner(System.in);
int num = in.nextInt(), temp = num, dig = in.nextInt();

while (dig<10&&dig>=0) {
dig = in.nextInt();
}
while (temp!=0) {
if (temp%10==dig) num=num*10+dig;
temp/=10;
}
35
Scanner in = new Scanner(System.in);
int num1=in.nextInt(), num2=in.nextInt(),count=0;
boolean flag=false;
while(flag==false) {

if (num1/10==0||num2/10==0)
flag=true;

if(num1==(num2%10*10+num2/10)||num1==num2) {
//checks for an exact copy or a reversed one.
count++;
System.out.printf("\n%d and %d are similar!",num1,num2);}

num1=in.nextInt();
num2=in.nextInt();

while (num1/100!=0||num2/100!=0) { //input verifier


System.out.println("try inputting the numbers again.");
num1=in.nextInt();
num2=in.nextInt();}
}
System.out.printf("\n%d pairs were similar.",count);

36
‫עשינו את זה בכיתה נראה לי‬
2
Scanner in = new Scanner(System.in);
String str;
for (int i=0;i<40;i++) {
str=in.next();
if(str.length()%2==0)
System.out.print(str+"\n");
}
3
Scanner in = new Scanner(System.in);
String str=in.next(),nums="1234567890";
boolean x=false;
for (int i=0;i<str.length();i++)
if(nums.contains(str.substring(i,i+1))) {
x=true;
}
if (x=true) System.out.print("The string has a number in it");
else System.out.print("The string doesn't have a number in it");

6
Scanner in = new Scanner(System.in);
String password = in.next(),chars="acdefghijklmnopqrstuvwxyz",nums="1234567890";
boolean flag = false;
while (flag==false) {
if (password.length()>=6) {
for (int i=0;i<chars.length();i++) {
if (password.contains(chars.substring(i, i)))
for (int q=0;q<nums.length();q++) {
if (password.contains(nums.substring(q, q)))
flag=true;
}
}
}
password = in.next(); }
if(flag) System.out.println(password+" is a valid password.");

You might also like