Click here to Skip to main content
15,880,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I coded a java class, now I need to change it to C++ code, but I am not expert in C++. Can any body change the code to C++ for me?
plz i need it!!

What I have tried:

Java
package mat;
import java.util.Scanner;
public class Mat {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("J_Baris : ");
        int x = in.nextInt();
        String deret="";
        System.out.print("J_Kolom : ");
        int y = in.nextInt();
        int i,j;
        int a[][] = new int[x][y];
        for(i=0;i<x;i++)
        {
            for(j=i+1;j<y;j++)
            {
                
                System.out.print("<"+(i+1)+","+(j+1)+"> = ");
                a[i][j] = in.nextInt();
                deret+=(i+1)+""+(j+1);
                
            }
        }
        System.out.println(deret);
        char tempd[] = new char[deret.length()];
        tempd = deret.toCharArray();
        char angka ='1';
        int z=1;
        int benar=0;
        int d = deret.length();
        for(i=0;i<d;i++)
        {
            if(z<y && i==(d-1))
            {
                angka++;
                benar=0;
                i=0;
                z++;
            }
            else if(tempd[i]==angka && benar==1)
            {
                tempd[i]=' ';
            }
            else if(tempd[i]==angka)
            {
                benar++;
            }
        }
        for(i=0;i<deret.length();i++)
        {
            if(tempd[i]==' ')
            {
                tempd[i]=' ';
            }
        }
        String deret1 = new String(tempd);
        System.out.println(deret1);
    }
}
Posted
Updated 26-Nov-17 20:25pm
v2
Comments
Suvendu Shekhar Giri 27-Nov-17 2:11am    
I would suggest to invest some time learning C++ first as it seems you'll be using C++ hereafter. There is a huge difference between these 2 and good news is, if you know Java then it should be very easy and quick to understand basic C++ concepts.

1 solution

The syntax of C++ and Java is similar, but the classes are very different. In C++ is are fat function libraries.

Please read the tutorial about strings and Basic Input/Output in C++ to learn to replay the scanner and println.

But you need to read or watch some beginner tutorials about C++ to get a kickstart.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900