Java Questions Answers-Java array (PartII)


Java array (PartII)

1. Change the following Java code from using a while loop to for loop:
x=1;
while(x<10){
  System.out.println(x+"\t");
  ++x;
}
Check answer 2. Change the following Java code from a while loop to a for loop:
int x;
Scanner sc=new Scanner(System.in);
x=sc.nextInt();
while(x!=10){
   System.out.println(x+"\t");
   x=sc.nextInt();
}
Check answer 3. What would be the output from the following Java code segment?
x=10;
while(x>5){
  System.out.println(x);
  x--;
}
Check answer 4. Change the following Java code from a for loop to a while loop:
for(i=1;i<50;i++)
  System.out.print(i+"\t");
Check answer 5. What would be printed from the following Java code segment?
for(i=20;i>0;i-=2)
  System.out.println(i);
Check answer 6. What would be printed from the following Java code segment?
for(x=1;x<=5;x++){
     for(y=1;y<=x;y++)
         System.out.print(x+"\t");
 
}
Check answer 7. Change the following Java code from a do while loop to a while loop:
x=0;
do{
  System.out.print(x+"\t");
  x++;
 }while(x<10);
Check answer


Comments




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.