1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/* Declare multiple variables in for loop Example This Java Example shows how to declare multiple variables in Java For loop using declaration block. */ public class DeclaringMultipleVariablesInForLoopExample { public static void main(String[] args) { /* * Multiple variables can be declared in declaration block of for loop. */ for(int i=0, j=1, k=2 ; i<5 ; i++) System.out.println("I : " + i + ",j : "+ j + ", k : " + k); /* * Please note that the variables which are declared, should be of same type * as in this example int. */ //THIS WILL NOT COMPILE //for(int i=0, float j; i < 5; i++); } } |
how will i make a code producing an output like this:
*****
****
***
**
*
???
[code]
for(int i=0;i<5;i++)
{
for(int j=5;j>i;j–)
System.out.println(“*”);
System.out.println();
}
[/code]
i want to output:
AAAAA
BBBB
CCC
DD
E
public class Main
{
public static void main(String[] args) {
int i,j;
for(i=5;i>0;i–)
{
for(j=i;j>0;j–)
{
System.out.print((char)(70-i));
}
System.out.println();
}
}
}
public class triangle {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int n=7;
for(int i=1;i<n;i++) {=”” for(int=”” j=”0;j<i;j++)” {=”” system.out.print(j+”=”” “);=”” }=”” system.out.println(“=”” “);=”” }=”” }=”” }=””>
public class piramid
{
public static void main(String arys[])
{
for(int i=0;i<5;i++)
{
for(int j=i;j<5;j++)
System.out.print(‘*’);
System.out.println();
}
}
}
for(int i=0; i<5; i++)
{
for(int j=i; j<5; j++)
System.out.print(“*”);
System.out.println(“”);
}
for(int i=1;i<=5;i++)
for(int j=5;j>=i;j–)
{
System.out.print(“*”);
if(j==i)
System.out.println(” “);
}
int i,j;
for (i=1; i<=5;i++){
for (j=5;j>=i;j–)
System.out.print(“*”);
System.out.println();
}
for(i=1;i<=5;i++)
{
for(j=5;j<=1;j–)
{ System.out.print(“*”);
}
System.out.println(” “);
}
use 2 for loop
for(int i=0;i<5;i++)
{
for(int j=5;j>i;j–)
{
System.out.print(“*”);
}
System.out.print(“
“);
[code]
for (int i = 5; i > 0; i -= 2) {
for (int j = 0; j < i; j++) {
System.out.print(‘*’);
}
System.out.println();
}
[/code]
[code]
void makePyramid()
{
for (int i = 0; i < 5; i++)
{
for (int j = i; i < 5; j++)
System.out.print(‘*’);
System.out.println();
}
}
[/code]
second for loop will never end
change it to
[code]
for(int j=i ; j<5 ; j++)
[/code]
Could you give me the code of this output:
*
**
***
****
*****
******
*******
******
*****
****
***
**
*
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
System.out.print(“*”);
System.out.print(“
“);
}
for(i=1;i<n;i++) {=”” for(j=”i;j<n;j++)” system.out.print(“*”);=”” system.out.print(“=”” “);=”” }=””>
[code]
for(int i=5; i>0; i–){
for(int x=0; x<i; x++{=”” system.out.print(“*”);=”” }=”” if(i!=”1)” system.out.println();=”” avoid=”” printing=”” line=”” if=”” final=”” output=”” }=”” [=”” code]=””>
Write a program that displays 3 integers then displays the highest number..
how can i make an output like this?
3
4
6
9
13
18
24
S=3+4+6+9+…+Tn
S= 3+4+6+…+T(n-1)+Tn
————————-(subtracting)
0=3+1+2+3+….+(n-1)-Tn
which means
Tn=3+(n*(n-1))/2
for(int i=1;i<=6;i++)
{
int x=3+(i*(i-1))/2;
System.out.println(x);
}
num=3;
for(i=0,k=0;i<6;i++,k++)
{
num=num+k;
System.out.println(num);
}
var y=3;
for(var i=0;i<7;i++)
{
y=y+i;
document.write(y);
document.write(“
“);
}
import java.util.*;
import java.text.*;
class pr
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int k=1;
for(int i=1;i<=7;i++)
{
int j=2;
System.out.print(j +k);
k=k+i;
System.out.println();
}
}
}
how will i make a code producing an output like this:
*
**
***
****
*****
using System;
class star
{
public static void Main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
Console.Write(“*”);
}
Console.WriteLine(“”);
}
}
}
*
**
***
****
*****
using System;
class star
{
public static void Main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
Console.Write(“*”);
}
Console.WriteLine(“”);
}
}
}
how can you make this? please i need to know.. thanks…
*********
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
*********
0 + 0 = 0
1 + 2 = 3
2 + 4 = 6
3 + 6 = 9
4 + 8 = 12
5 + 10 = 15
6 + 12 = 18
7 + 14 = 21
8 + 16 = 24
9 + 18 = 27
[code]
public class PrintSequenceAddition {
public void createSeq(){
for(int i=0; i<=9; i++){
System.out.println(i +”+” +(i*2) +”=” +(i + (i*2)));
}
}
public static void main(String[] args) {
PrintSequenceAddition psa = new PrintSequenceAddition();
psa.createSeq();
}
}
[/code]
*
*
*
*
*
please answer
class abc
{
public static void main(String args[])
{
for(int i=1;i<6;i++)
{
System.out.println(“*”);
}
}
}
public static void main(String args[])
{
for { i=1; i<=5; i++}
{
System.out.println(” * “);
}
}
import java.io.*;
public class ans
{
public static void main(String args[])
{
for(int i=0;i<5;i++)
{
System.out.println(“*”);
}
}
}
1
2 2
3 3 3
4 4 4 4
3 3 3
2 2
1
class New1
{
public static void main(String[] args)
{
for(int a = 1;a <= 4;a++){for(int b = 1;b <= a;b++)
{System.out.print(a);} System.out.println();}
for(int c = 3;c >= 1;c–){for(int d = 1;d <= c;d++)
{System.out.print(c);}System.out.println();}
}
}
######
#####
####
###
##
#
Thanks!!
[code]
public class JavaPyramid2 {
public static void main(String[] args) {
for(int i=5; i>0 ;i–){
for(int j=0; j < i; j++){
System.out.print(“#”);
}
//generate a new line
System.out.println(“”);
}
}
}
[/code]
######
#####
####
###
##
#
************
***** ******
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
***** ******
************
1
1 2
1 2 3
for(int i=1;i<4;i++)
{
for(int j=0;j<i;j++) {=”” system.out.print(‘j’);=”” }=”” system.out.println();=”” }=””>
how to produce this output?
Enter a string: abba
The reverse of the entered string is abba.
The entered strig is a palindrome
import java.util.*;
public class palindrome {
static Scanner w = new Scanner(System.in);
public static void main(String args[]){
for(int i = 1; i > 0; i++){
String strOriginalA;
String strOriginalB;
System.out.print(“Enter your word : “);
strOriginalA = w.next();
strOriginalB = new StringBuffer(strOriginalA).reverse().toString();
System.out.println(“Palindrome : ” + strOriginalB);
if(strOriginalA.equalsIgnoreCase(strOriginalB))
System.out.println(“TRUE”);
else
System.out.println(“False”);
}
}
}
K
SADV
SDVSVD
XSDVSDFV
SD
SDFSDFGSDGH
FN FH
FMTH
GFHF
MHF
FY
F
FTT
YF
JYF
TY
FTY
How can I do this?
1
212
32123
4321234
543212345
65432123456
etc?
I have to loop a program containing if statements, 3 times. a double has to be input by the user and the output has to show either POSITIVE, NEGATIVE or ZERO>
Please help
pls give solution in java
Using a for loop:
1 4 7 10 13 16 19 22 25 28 31 34 37 40
Should count to 40 by 3’s. Thank you!!
for (int ctr = 1; ctr <= 40; ctr += 3)
System.out.print(ctr + ” “);
public static void main(String args[])
{
int i,a,b=1;
a=Integer.parseInt(args[0]);
while(b<40)
{
System.out.println(b);
b=b+3;
}
}
public static void main(String[] args)
{
int i;
for(i= 1; i<= 40; i= i+3)
{
System.out.print(i);
}
System.out.println(” “);
}
you are amazing the way u pop out code
*
***
*****
*******
*****
***
*
public class diamond
{
public static void main(String args[])
{
int i , j;
for (i=0;i<=5;i++)
{
for (j=0;j<i;j++) {=”” system.out.print(“*”);=”” }=”” system.out.println(“”);=”” }=”” }=”” }=”” }=””>
class New1
{
public static void main(String[] args)
{
for(int a = 1;a <= 7;a+=2){for(int b = 1;b <= a;b++)
{System.out.print(“*”);} System.out.println();}
for(int c = 5;c >= 1;c-=2){for(int d = 1;d <= c;d++)
{System.out.print(“*”);}System.out.println();}
}
}
class Star
{
public static void main(String a[])
{
Character x=0;
Character y=0;
while (x<5)
{
x++;
y=0;
while(y<x) {=”” y++;=”” system.out.print(“*”);=”” }=”” system.out.print(“\n”);=”” }=”” {=”” character=”” n=”5;” character=”” m=”0;” while=”” (0<n)=”” {=”” n–;=”” m=”0;” while(m<n)=”” {=”” m++;=”” system.out.print(“*”);=”” }=”” system.out.print(“\n”);=”” }=”” }=”” }=”” }=””>
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
can u give one logic for this using for loop
for(int a=1;a<=5;a++){
for(b=1;b<=5;b++){
System.out.println(a);
}
}
This is wrong, it would give an output something like
1
1
1
1
1
2
2
2
2
2
….5
The correct answer should be
for(int a=1; a<=5;a++){
for(int b=1;b<=a;b++){
System.out,printf(a);
}
system.out.println(“”);
}
import java.util.*;
class NumberPeramid
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.println(“Enter the number”);
int x=s.nextInt();
for(int i=1; i<=x; i++)
{
for(int j=1; j<=i; j++)
{
System.out.print(i);
}
System.out.println (” \n “);
}
}
}
how can i make an out put like this
*
**
***
****
*****
******
*******
********
*********
for(int z = 9 ; z >=1 ; z –)
{
for(int x = 9 ; x >=z ; x –)
{
System.out.print(“*”);
}
System.out.println(“”);
}
output :
*
**
***
****
*****
******
*******
********
*********
public class Alpha{
public static void main (String[] args) {
for(int i=1;i<10;i++)
{
for(int j=0;j<i;j++) {=”” system.out.print(“*”);=”” }=”” system.out.println();=”” }=”” }=”” }=””>
how to output this:
*
**
***
****
*****
******
@@@@@*
@@@@**
@@@***
@@****
@*****
thank you for the response 😉
for(int z =1 ; z <=5 ; z++)
{
for(int x = 1 ; x <=5-z ; x++)
{
System.out.print(“@”);
}
for(int x = 1 ; x <=z ; x++)
{
System.out.print(“*”);
}
System.out.println();
}
for(int i=0; i<5; i++)
{
for(int j=i; j<5; j++)
System.out.print(“*”);
System.out.println(“”);
}
create a java programm that will accept an integer number and will display the FF:
Example:
Enter Starting number: 1
Enter Ending Number : 20
enter step number : 2
output must be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
thx for those who help me…
for(int z = 1 ; z <= 9 ; z++)
{
if(z==0)
{
}
else if(z==1)
{
}
else if(z>1)
{
System.out.println(z);
}
}
guys can u give me a code for this output?
1
2
3
4
5
6
thx
public static void main(String[] args)
{
int i;
for(i=1;i<=6;i=i+1)
{
System.out.print(i);
}
System.out.println(” “);
}
for(int z = 1 ; z <= 6 ; z++)
{
System.out.println(z);
}
code with this output///
0
1, 0
2, 1, 0
3, 2, 1, 0
4, 3, 2, 1, 0
5, 4, 3, 2, 1, 0
6, 5, 4, 3, 2, 1, 0
7, 6, 5, 4, 3, 2, 1, 0
8, 7, 6, 5, 4, 3, 2, 1, 0
9, 8, 7, 6, 5, 4, 3, 2, 1, 0
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
for (int i = 10; i >= 0; i–) {
for (int j = (10 – i); j >= 0; j– ) {
System.out.print(j);
if (j != 0) System.out.print(“, “);
}
System.out.println();
}
how can i make an out put like this…that exchanges the values in two variables.
LIKE THAT THE OUTPUT :
Before—a: 7, b:100
After – a: 100, b:7
What about create int c, then a -> c, b -> a, c -> b?
…or…
a = a + b; //107
b = a – b; //7
a = a – b; //100
I need you help in doing this output
6
9
12
15
18
21
for(int a = 6 ; a < 100 ; a = a +3)
{
System.out.println(a);
}
code for two input:
example:
year/section: 2 / A
how can i make an out put like this
* *
** **
*** ***
**** ****
**********
**********
**** ****
*** ***
** **
* *
what is the code with explain
Enter the N values 5
one
two
three
four
five
Write an application that calculates the air temperature given the number of cricket chirps per minute. A user supplies the number of chirps per minute.
Output:
Enter the number of chirps/minute: 99
The temperature is 19.0C.
plssssss..help me
how can i make an out put like this…that exchanges the values in two variables.
LIKE THAT THE OUTPUT :
Before—a: 7, b:100
After – a: 100, b:7
help me plsssss
yes u can try by urself…
Write a program that prompts an instructor for.
1. the number of students in his/her class, and
2. the number of grades assigned to each student,
and determines the average grade for each student. Grades are whole numbers, but an average may be a decimal number.
Sample Run:
Number of Students: 2
Number of grades per student: 2
Grades for student 1
1: 90
2: 88
Average: 89
Grades for student 2
1: 76
2: 78
Average: 77
how can i do this, plssss i need your help guiz.
0
12
345
6789
NESTED LOOP PROGRAM